<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>博客后台 - 登录</title>

    <link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
</head>

<body class="gray-bg">

    <div class="middle-box text-center loginscreen  animated fadeInDown">
        <div>
            <div>

                <h1 class="logo-name">GBlog</h1>

            </div>
            <h3>GBlog后台登录</h3>

            <div>
                <div class="form-group">
                    <input name="username" class="form-control" placeholder="用户名" required="">
                </div>
                <div class="form-group">
                    <input name="password" type="password" class="form-control" placeholder="密码" required="">
                </div>
                <button id="login-button" type="submit" class="btn btn-primary block full-width m-b">登 录</button>


                <p class="text-muted text-center"> <a href="login.html#"><small>忘记密码了？</small></a> | <a href="register.html">申请一个新账号</a>
                </p>

            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>
    <script src="js/plugins/jsencrypt/jsencrypt.js"></script>
    <script src="js/plugins/toastr/toastr.min.js"></script>

    <script type="text/javascript">
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "progressBar": true,
            "positionClass": "toast-top-center",
            "onclick": null,
            "showDuration": "400",
            "hideDuration": "1000",
            "timeOut": "7000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        }
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCk5QaEr41BfEWIXOsDeB2R9kuBYeoHcfMZvl87HS9F55nC+WGr11YyRdskHloRzYKJhjcce+7fQeKY0MrPXCJG40I5Nu/mRU1W68FXcC3y966LBoIkezkMmLUQ6mDj5oky0kuIR0xeAzE5NGTF7LLAT8H06+uBWX3nHJkR70E0pwIDAQAB");
        $(function(){
            $(document).keydown(function(event){
                if(event.keyCode==13){
                    $("#login-button").click();
                }
            });
            $("#login-button").click(function(){
                var username=$("input[name='username']").val();
                var password=$("input[name='password']").val();
                if(username==null||password==null||username==""||password=='')
                    return;
                password=encrypt.encrypt(password);
                console.log(username+"\n-----\n"+password);
                $.ajax({
                    url:'/api/pass/login',
                    type:'post',
                    data:{
                        username:username,
                        password:password
                    },
                    success:function(resp){
                        if(resp.status==200){
                            window.location.href="/index.html";
                        }else{
                            toastr.info(resp.message);
                        }
                    }
                });
            });
        });
    </script>
</body>

</html>
